package com.hd.controller.activiti.example;

import com.hd.controller.base.BaseController;
import com.hd.entity.activiti.*;
import com.hd.entity.activiti.example.Leave;
import com.hd.service.activiti.*;
import com.hd.service.activiti.example.LeaveService;
import com.hd.util.StringUtils;
import com.hd.util.result.PageInfo;
import com.hd.util.result.Result;
import org.activiti.engine.*;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 请假申请
 * 
 * @author hzhh123 2018年7月30日下午7:23:15
 */
@Controller
@RequestMapping("/example/leave")
public class LeaveController extends BaseController {
	private static final Logger log=LoggerFactory.getLogger(LeaveController.class);
	//流程定义KEY
	private static final String PROC_DEF_KEY = "leave";
	//起始节点KEY
	private static final String START_KEY="startevent1";
	@Autowired
	private ActivitiService activitiService;
	@Autowired
	private LeaveService leaveService;
	@Autowired
	private ProcessInstanceEntityService processInstanceEntityService;
	@Autowired
	private TaskService taskService;
	@Autowired
	private RuntimeService runtimeService;
	@Autowired
	private ProcessTypeService processTypeService;
	@Autowired
	private ElementDefService elementDefService;
	@Autowired
	private TempStoageTaskService tempStoageTaskService;
	@Autowired
	private HistoryService historyService;
	@Autowired
	private CommentEntityService commentEntityService;
	/**
	 * 请假流程管理页面
	 * @return
	 */
	@RequestMapping("/toleavelist")
	public String toLeavelist() {
		return "jsp/activiti/example/leave/leaveList";
	}
	/**
	 * 流程发起初始化页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/toStart")
	public String startPage(Model model) throws Exception {
		/*String startKey="startevent1";
		Map<String,Object>map=new HashMap<String,Object>();
		List<com.hd.entity.activiti.UserTask>tasks=elementDefService.getNextTaskNode(PROC_DEF_KEY,startKey,map,null,getUserId());
		model.addAttribute("tasks", tasks);*/
		return "jsp/activiti/example/leave/leaveStart";
	}
	
	
    /**
     * 查询当前用户请假列表
     * @param page
     * @param rows
     * @param sort
     * @param order
     * @return
     */
    @RequestMapping(value="/dataGrid",method=RequestMethod.POST)
    @ResponseBody
    public Object dataGrid(Leave leave, Integer page, Integer rows, String sort, String order) {
        PageInfo pageInfo = new PageInfo(page, rows, sort, order);
        Map<String,Object>condition=new HashMap<String,Object>();
          if(StringUtils.isNotNull(leave.getStatus())){
              condition.put("status", leave.getStatus());
          }
          if(StringUtils.isNotBlank(leave.getTitle())){
              condition.put("title", leave.getTitle());
          }
          if(StringUtils.isNotBlank(leave.getProcessInstanceId())){
              condition.put("processInstanceId", leave.getProcessInstanceId());
          }
        if(leave.getLeaveDateStart()!=null) {
            condition.put("leaveDateStart", leave.getLeaveDateStart());
        }
        condition.put("userid", getUserId());
        if(leave.getLeaveDateEnd()!=null) {
            condition.put("leaveDateEnd", leave.getLeaveDateEnd());
        }
        pageInfo.setCondition(condition);
        leaveService.selectDataGrid(pageInfo);
        return pageInfo;
    }

	/**
	 * 暂存
	 * @param leave
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/tempStorage")
    public Object tempStorage(Leave leave,HttpServletRequest request){
		String title = "";
		leave.setStatus(BaseVO.TEMP_STOAGE);// 暂存
		if (!StringUtils.isNotNull(leave.getTitle())) {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			title = df.format(leave.getLeaveDate()) + leave.getUserName() + "的请假申请";
			leave.setTitle(title);
		} else {
			title = leave.getTitle();
		}
		// 保存数据
		leave.setPrevUserid(leave.getUserid());
		ProcessType processType = processTypeService.getByKey(PROC_DEF_KEY);
		String processTitle="请假申请";
		String businessid="";
		if(processType!=null) {
			processTitle=processType.getName();
			businessid=processType.getId();
			leave.setBusinessType_(processType.getName());
			leave.setBusinessKey_(PROC_DEF_KEY);
		}else {
			leave.setBusinessType_(processTitle);
			leave.setBusinessKey_(PROC_DEF_KEY);
		}
		leave.setUserid_(leave.getUserid());
		leave.setTitle_(title);
		leave.setUserName_(leave.getUserName());
		leaveService.save(leave);
		Map<String,Object>map=new HashMap<String,Object>();
		elementDefService.setNextNodeAssignees(PROC_DEF_KEY,START_KEY,leave.getId(),map,request);
		logger.info("暂存");
		TempStoageTask tempStoageTask=new TempStoageTask();
		tempStoageTask.setBusinessKey(PROC_DEF_KEY);
		tempStoageTask.setTitle(title);
		tempStoageTask.setUserid(leave.getUserid());
		tempStoageTask.setUserName(leave.getUserName());
		tempStoageTask.setObjId(leave.getId());
		tempStoageTask.setBusinessType(processTitle);
		tempStoageTask.setTableName("t_leave");
		tempStoageTask.setCreateTime(new Date());
		tempStoageTaskService.save(tempStoageTask);
		return renderSuccess("暂存成功！");
	}

	/**
	 * 提交申请
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/submitProcessInstance")
	public Object submitProcessInstance(String id){
    	Leave leave=leaveService.get(id);
		Result result = new Result();
		String title = "";
		// 启动流程
		try {
			leave.setStatus(BaseVO.PENDING);// 审批中
			if (!StringUtils.isNotNull(leave.getTitle())) {
				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				title = df.format(leave.getLeaveDate()) + leave.getUserName() + "的请假申请";
				leave.setTitle(title);
			} else {
				title = leave.getTitle();
			}
			// 保存数据
			leave.setPrevUserid(leave.getUserid());
			ProcessType processType = processTypeService.getByKey(PROC_DEF_KEY);
			String processTitle="请假申请";
			String businessid="";
			if(processType!=null) {
				processTitle=processType.getName();
				businessid=processType.getId();
				leave.setBusinessType_(processType.getName());
				leave.setBusinessKey_(PROC_DEF_KEY);
			}else {
				leave.setBusinessType_("请假申请");
				leave.setBusinessKey_(PROC_DEF_KEY);
			}
			leave.setUserid_(leave.getUserid());
			leave.setTitle_(title);
			leave.setUserName_(leave.getUserName());
			leaveService.update(leave);
			String processInstanceId=leaveService.startProcessInstance(PROC_DEF_KEY,leave);
			com.hd.entity.activiti.ProcessInstanceEntity pi = new com.hd.entity.activiti.ProcessInstanceEntity();
			pi.setProcessInstanceId(processInstanceId);
			pi.setStartTime(new Date());
			pi.setStatus(com.hd.entity.activiti.ProcessInstanceEntity.RUN_STATUS);
			pi.setTitle(title);
			pi.setUserid(leave.getUserid());
			pi.setUserName(leave.getUserName());
			pi.setBusinessKey(PROC_DEF_KEY);
			pi.setBusinessType(processTitle);
			pi.setBusinessId(businessid);
			processInstanceEntityService.save(pi);
			result.setSuccess(Boolean.TRUE);
			result.setMsg("请假流程已启动，流程ID：" + processInstanceId);
			logger.info("processInstanceId: " + processInstanceId);
			tempStoageTaskService.delete(PROC_DEF_KEY,leave.getId());
		} catch (ActivitiException e) {
			result.setSuccess(Boolean.FALSE);
			if (e.getMessage().indexOf("no processes deployed with key") != -1) {
				logger.warn("没有部署流程!", e);
				result.setMsg("没有部署流程，请联系系统管理员，在[流程定义]中部署相应流程文件！");
			} else {
				logger.error("启动请假流程失败：", e);
				result.setMsg("启动请假流程失败，系统内部错误！");
			}
			throw e;
		} catch (Exception e) {
			logger.error("启动请假流程失败：", e);
			result.setSuccess(Boolean.FALSE);
			result.setMsg("启动请假流程失败，系统内部错误！");
			throw e;
		}
		return result;
	}
    
	/**
	 * 启动流程
	 * 
	 * @param leave
	 * @return
	 */
    @ResponseBody
	@RequestMapping("/startProcessInstance")
	public Object startProcessInstance(Leave leave,HttpServletRequest request) {
    	String id=leave.getId();
		Result result = new Result();
		String title = "";
		// 启动流程
		try {
			leave.setStatus(BaseVO.PENDING);// 审批中
			if (!StringUtils.isNotNull(leave.getTitle())) {
				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				title = df.format(leave.getLeaveDate()) + leave.getUserName() + "的请假申请";
				leave.setTitle(title);
			} else {
				title = leave.getTitle();
			}
			// 保存数据
			leave.setPrevUserid(leave.getUserid());
			ProcessType processType = processTypeService.getByKey(PROC_DEF_KEY);
			String processTitle="请假申请";
			String businessid="";
			if(processType!=null) {
				processTitle=processType.getName();
				businessid=processType.getId();
				leave.setBusinessType_(processType.getName());
				leave.setBusinessKey_(PROC_DEF_KEY);
			}else {
				leave.setBusinessType_("请假申请");
				leave.setBusinessKey_(PROC_DEF_KEY);
			}
			leave.setUserid_(leave.getUserid());
			leave.setTitle_(title);
			leave.setUserName_(leave.getUserName());
			leaveService.save(leave);
			Map<String,Object>map=new HashMap<String,Object>();
			elementDefService.setNextNodeAssignees(PROC_DEF_KEY,START_KEY,leave.getId(),map,request);
			String processInstanceId=leaveService.startProcessInstance(PROC_DEF_KEY,leave);
			com.hd.entity.activiti.ProcessInstanceEntity pi = new com.hd.entity.activiti.ProcessInstanceEntity();
			pi.setProcessInstanceId(processInstanceId);
			pi.setStartTime(new Date());
			pi.setStatus(com.hd.entity.activiti.ProcessInstanceEntity.RUN_STATUS);
			pi.setTitle(title);
			pi.setUserid(leave.getUserid());
			pi.setUserName(leave.getUserName());
			pi.setBusinessKey(PROC_DEF_KEY);
			pi.setBusinessType(processTitle);
			pi.setBusinessId(businessid);
			processInstanceEntityService.save(pi);
			log.info("id={}",id);
			if(StringUtils.isNotNull(id)){
				//暂存提交需要删除暂存数据
				tempStoageTaskService.delete(PROC_DEF_KEY, id);
			}
			result.setSuccess(Boolean.TRUE);
			result.setMsg("请假流程已启动，流程ID：" + processInstanceId);
			logger.info("processInstanceId: " + processInstanceId);
		} catch (ActivitiException e) {
			result.setSuccess(Boolean.FALSE);
			if (e.getMessage().indexOf("no processes deployed with key") != -1) {
				logger.warn("没有部署流程!", e);
				result.setMsg("没有部署流程，请联系系统管理员，在[流程定义]中部署相应流程文件！");
			} else {
				logger.error("启动请假流程失败：", e);
				result.setMsg("启动请假流程失败，系统内部错误！");
			}
			throw e;
		} catch (Exception e) {
			logger.error("启动请假流程失败：", e);
			result.setSuccess(Boolean.FALSE);
			result.setMsg("启动请假流程失败，系统内部错误！");
			throw e;
		}
		return result;
	}
	
	/**
	 * 跳转到审批页面
	 * @param taskId 任务id
	 * @param model
	 * @return
	 */
	@RequestMapping("/toApproval")
	public String toApproval(String taskId,String processInstanceId,Model model) {
		model.addAttribute("taskId",taskId);
		Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
		model.addAttribute("taskDefKey", task.getTaskDefinitionKey());
		model.addAttribute("procDefId", task.getProcessDefinitionId());
		model.addAttribute("processInstanceId",processInstanceId);
		return "jsp/activiti/example/leave/leave_todo";
	}
	
	  /**
     * 待办实例信息
     * @param taskId
     * @return
     */
    @ResponseBody
    @RequestMapping("/toApproval/{taskId}")
	public Object toApproval(@PathVariable("taskId")String taskId,String currentUserid) {
    	Map<String,Object>map=new HashMap<String,Object>();
		//查询任务
		Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
		//查询流程实例
		String processInstanceId=task.getProcessInstanceId();
		ProcessInstance pi=runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId)
				.singleResult();
		//查询出实体
		Leave leave=(Leave) this.runtimeService.getVariable(pi.getId(), "entity");
		leave.setProcessInstanceId(processInstanceId);
		leave.setTask(task);
		//查询出评论
		String taskDefinitionKey=task.getTaskDefinitionKey();
		List<CommentVO>comments=activitiService.getCommentsByProcessInstanceId(processInstanceId);
		//业务处理,根据taskDefinitionKey跳转页面
		map.put("taskDefinitionKey", taskDefinitionKey);
		//任务执行人
		String assigneeOrCandidateUser=(String) activitiService.findTodoTaskAssigneeOrCandidateUsers(processInstanceId)
											.get("userNames");
		map.put("assigneeOrCandidateUser", assigneeOrCandidateUser);
		map.put("leave", leave);
		map.put("comments", comments);
		map.put("taskId", taskId);
		map.put("procDefId", pi.getProcessDefinitionId());
		map.put("taskDefKey", task.getTaskDefinitionKey());
		String startKey=task.getTaskDefinitionKey();
		Map<String,Object>paramMap=new HashMap<String,Object>();
		String procDefId=pi.getProcessDefinitionId();
		List<com.hd.entity.activiti.UserTask>tasks=elementDefService.getNextTaskNode(procDefId,PROC_DEF_KEY,startKey,paramMap,leave.getId(),currentUserid);
		map.put("tasks", tasks);
		return map;
	}
	
	/**
	 * 完成任务
	 * @param taskId 任务id
	 * @param content 审批意见
	 * @param id 请假申请id
	 * @param completeFlag 审批标志：同意、驳回
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/completeTask/{taskId}")
	public Object completeTask(@PathVariable("taskId")String taskId,
		String content,String id,Boolean completeFlag,String currentUserid,HttpServletRequest request) {
		Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
		Result result=new Result();
		 try {
	            Leave leave = this.leaveService.get(id);
	            Leave bean = (Leave) this.runtimeService.getVariable(leave.getProcessInstanceId(), "entity");
	            Map<String, Object> variables = new HashMap<String, Object>();
	            //保存任务执行人
	            Map<String,Object>map=new HashMap<String,Object>();
	     		elementDefService.setNextNodeAssignees(PROC_DEF_KEY,task.getTaskDefinitionKey(),leave.getId(),map,request);
	            variables.put("isPass", completeFlag);
	            variables.put("isPass", completeFlag);
	            if(!completeFlag){
	            	bean.setTitle_("【"+bean.getTitle()+"】的流程审批失败,需修改后重新提交！");
	                leave.setStatus_(BaseVO.APPROVAL_ADJUST);
	                leave.setStatus(BaseVO.APPROVAL_ADJUST);
	                variables.put("entity", bean);
	                variables.put("prevUserid",currentUserid);
	                variables.put("objId", leave.getId());
	                  //发起者
	                variables.put("startUserid", leave.getUserid());
	            }
	            if(!completeFlag) {
	            	if(!StringUtils.isNotNull(content)) {
	            		content="不同意";
	            	 }
	            }else {
	            	if(!StringUtils.isNotNull(content)) {
	            		content="同意";
	            	 }
	            }
	            // 完成任务
	            this.activitiService.completeTask(taskId, content, currentUserid, variables);
	            if(completeFlag){
	                //此处需要修改，不能根据人来判断审批是否结束。应该根据流程实例id(processInstanceId)来判定。
	                //判断指定ID的实例是否存在，如果结果为空，则代表流程结束，实例已被删除(移到历史库中)
	                ProcessInstance pi = this.runtimeService.createProcessInstanceQuery().processInstanceId(leave.getProcessInstanceId()).singleResult();
	                if(pi==null){
	                    leave.setStatus(BaseVO.APPROVAL_SUCCESS);
	                    //设置流程完成
	                    com.hd.entity.activiti.ProcessInstanceEntity instance = processInstanceEntityService.get(leave.getProcessInstanceId());
	                    instance.setEndTime(new Date());
	                    instance.setStatus(3);
	                    processInstanceEntityService.update(instance);
	                }
	            }

	            this.leaveService.update(leave);
	            result.setSuccess(Boolean.TRUE);
	            result.setMsg("任务办理完成！");
	        } catch (ActivitiObjectNotFoundException e) {
	            result.setSuccess(Boolean.FALSE);
	            result.setMsg("此任务不存在，请联系管理员！");
	            throw e;
	        } catch (ActivitiException e) {
	            result.setSuccess(Boolean.FALSE);
	            result.setMsg("此任务正在协办，您不能办理此任务！");
	            throw e;
	        } catch (Exception e) {
	            result.setSuccess(Boolean.FALSE);
	            result.setMsg("任务办理失败，请联系管理员！");
	            throw e;
	        }
	        return result;
	}
	
	/**
     * 调整请假申请
     * @param taskId
     * @param processInstanceId
     * @param reApply
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/modifyLeave/{taskId}", method = RequestMethod.POST)
    @ResponseBody
    public Object modifyLeave(
            @ModelAttribute("leave") Leave leave,
            @PathVariable("taskId") String taskId,
            @RequestParam("processInstanceId") String processInstanceId,
            @RequestParam("reApply") Boolean reApply,HttpServletRequest request
           ) throws Exception{
        Result result = new Result();
        Map<String, Object> variables = new HashMap<String, Object>();
        Map<String,Object>map=new HashMap<String,Object>();
        String content="调整申请";
        if(reApply){
        	Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        	elementDefService.setNextNodeAssignees(PROC_DEF_KEY,task.getTaskDefinitionKey(),leave.getId(),map,request);
            //修改请假申请
            leave.setTitle_(leave.getTitle());
            leave.setStatus(BaseVO.PENDING);
            result.setSuccess(Boolean.TRUE);
            leave.setBusinessKey_("leave");
            leave.setBusinessType_("请假申请");
            leave.setUserid_(leave.getUserid());
            leave.setUserName_(leave.getUserName());
            result.setMsg("任务办理完成，请假申请已重新提交！");
        }else{
            leave.setTitle_("【"+leave.getTitle()+"】的流程已取消！");
            leave.setStatus(BaseVO.APPROVAL_FAILED);
            result.setSuccess(Boolean.TRUE);
            com.hd.entity.activiti.ProcessInstanceEntity instance = processInstanceEntityService.get(leave.getProcessInstanceId());
            instance.setEndTime(new Date());
            instance.setStatus(BaseVO.APPROVAL_FAILED_NUMBER);
            processInstanceEntityService.update(instance);
            result.setMsg("任务办理完成，已经取消您的请假申请！");
            content="取消申请";
        }
        try {
        	this.leaveService.update(leave);
            variables.put("entity", leave);
            variables.put("reApply", reApply);
            variables.put("objId", leave.getId());
            this.activitiService.completeTask(taskId, content, leave.getUserid(), variables);
        } catch (ActivitiObjectNotFoundException e) {
            result.setSuccess(Boolean.FALSE);
            result.setMsg("此任务不存在，请联系管理员！");
            throw e;
        } catch (ActivitiException e) {
            result.setSuccess(Boolean.FALSE);
            result.setMsg("此任务正在协办，您不能办理此任务！");
            throw e;
        } catch (Exception e) {
            result.setSuccess(Boolean.FALSE);
            result.setMsg("任务办理失败，请联系管理员！");
            throw e;
        }
        return result;
    }

    /**
     * 查看详细信息
     * @param processInstanceId
     * @param model
     * @return
     */
    @RequestMapping("/viewleaveinfo/{processInstanceId}")
    public String viewleaveinfo(@PathVariable("processInstanceId")String processInstanceId,Model model) {
    	// Leave leave = leaveService.getByProcessInstanceId(processInstanceId);
    	// model.addAttribute("leave", leave);
    	// List<CommentVO>comments=activitiService.getCommentsByProcessInstanceId(processInstanceId);
    	// model.addAttribute("comments", comments);
    	model.addAttribute("processInstanceId", processInstanceId);
    	return "jsp/activiti/example/leave/leaveView";
    }
    /**
     * 获取详细信息
     * @param processInstanceId
     * @return
     */
    @ResponseBody
    @RequestMapping("/getDetail")
    public Object getDetail(String processInstanceId){
    	Map<String,Object>dataMap=new HashMap<>();
    	Leave leave = leaveService.getByProcessInstanceId(processInstanceId);
    	List<CommentVO>comments=activitiService.getCommentsByProcessInstanceId(processInstanceId);
    	dataMap.put("leave", leave);
    	dataMap.put("comments", comments);
		if(comments.size()>0){
			HistoricProcessInstance pd=historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId)
					.singleResult();
			String procdefId=pd.getProcessDefinitionId();
			List<ElementDef>elementDefs=elementDefService.find(procdefId);
			dataMap.put("elementDefs",elementDefs);
			List<CommentEntity>commentEntities=commentEntityService.findPrintComments(processInstanceId);
			dataMap.put("commentEntities",commentEntities);

		}
		return dataMap;
    }
    /**
     * 作废
     * @param processInstanceId
     * @return
     */
    @RequestMapping("/cancel")
    @ResponseBody
    public Object cancel(String processInstanceId) {
    	leaveService.deleteLeaveProcess(processInstanceId);
    	return renderSuccess("作废成功！");
    }

    /**
     * 删除
     * @param  id [description]
     * @return    [description]
     */
    @ResponseBody
	@RequestMapping("delete")
	public Object delete(String id){
    	leaveService.delete(id);
    	return renderSuccess("删除成功！");
	}

	/**
	 * 跳转到编辑页面
	 * @param  id    [description]
	 * @param  model [description]
	 * @return       [description]
	 */
	@RequestMapping("/editPage")
	public String editPage(String id,Model model){
		// Leave leave=leaveService.get(id);
		// model.addAttribute("leave",leave);
		// String startKey="startevent1";
		// Map<String,Object>map=new HashMap<String,Object>();
		// List<com.hd.entity.activiti.UserTask>tasks=elementDefService.getNextTaskNode(PROC_DEF_KEY,startKey,map,leave.getId(),getUserId());
		// model.addAttribute("tasks", tasks);
		model.addAttribute("id", id);
		return "jsp/activiti/example/leave/leave_edit";
	}

	  /**
     * 查询请假暂存数据|发起请求
     * @param id
     * @return
     */
    @RequestMapping("/findOne")
    @ResponseBody
    public Object findOne(@RequestParam(name="id",required=false)String id,String userid) {
    	Map<String,Object>dataMap=new HashMap<>();
    	Leave leave=new Leave();
    	if(StringUtils.isNotNull(id)) {
    		 leave = leaveService.get(id);
    	}else {
    		id=null;
    	}
    	String startKey=START_KEY;
		Map<String,Object>map=new HashMap<String,Object>();
		List<com.hd.entity.activiti.UserTask>tasks=elementDefService.getNextTaskNode(null,PROC_DEF_KEY,startKey,map,id,userid);
		dataMap.put("leave", leave);
		dataMap.put("tasks", tasks);
		dataMap.put("success",true);
    	return dataMap;
    }
    
	/**
	 * 编辑
	 * @param  leave   [description]
	 * @param  request [description]
	 * @return         [description]
	 */
	@ResponseBody
	@RequestMapping("/edit")
	public Object edit(Leave leave,HttpServletRequest request){
		leave.setStatus(BaseVO.TEMP_STOAGE);
		leaveService.update(leave);
		Map<String,Object>map=new HashMap<String,Object>();
		String startKey=START_KEY;
		elementDefService.setNextNodeAssignees(PROC_DEF_KEY,startKey,leave.getId(),map,request);
		return renderSuccess("编辑成功！");
	}
}
